{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 第十四届中国大学生服务外包创新创业大赛百度赛道-智慧医疗赛题baseline 2\n",
    "\n",
    "## 比赛介绍\n",
    "中国大学生服务外包创新创业大赛是中国高等教育学会全国普通高校学科竞赛排行榜内竞赛，本届赛事，百度飞桨设立了“基于百度飞桨的3D 医疗数据解析平台”的赛道，参赛获奖有助于保研加分。\n",
    "\n",
    "## 赛题背景\n",
    "腹部多器官分割一直是医学图像分析领域最活跃的研究领域之一，其作为一项基础技术，在支持疾病诊断，治疗规划等计算机辅助技术发挥着重要作用。近年来，基于深度学习的方法在该领域中获得了巨大成功，却也暴露出了一个迫切问题: 当前社区缺乏一个大规模、多样性、且符合真正临床场景的综合基准数据集来开发/评估对应的算法。虽然目前已有几个腹部器官分割数据集，它们的标注器官和标注例子数目却相对有限，仍然限制了现代深度模型的力量，也难以对提出的不同方法进行全面和公平的评估。\n",
    "\n",
    "为了解决上述问题，进一步促进医疗图像分割技术的发展，深圳市大数据研究院、香港中文大学（深圳）、香港大学、中山大学等机构联合深圳市龙岗区人民医院、深圳市龙岗中心医院提出了多模态腹部分割数据集（AMOS），一个大规模，多样性的，收集自真实临床场景下的腹部多器官分割基准数据。\n",
    "\n",
    "本次竞赛抽取AMOS2022数据集中的部分数据作为训练和评测数据。\n",
    "**注意：本比赛只允许使用提供的数据集。**\n",
    "\n",
    "\n",
    "## 任务说明\n",
    "参赛者利用提供的训练数据，实现对腹部多器官图像的器官分割。\n",
    "\n",
    "## 数据集介绍\n",
    "多器官数据集共有15个器官的标注，包括脾脏、右肾、左肾、胆囊、食道、肝、胃、主动脉、下腔静脉、胰腺、右肾上腺、左肾上腺、十二指肠、膀胱、前列腺/子宫。本数据集共包含160个训练数据，40个测试数据。  \n",
    "![](https://ai-studio-static-online.cdn.bcebos.com/83b784b1076a4b0a8fa88a70706b00fede66f0570cc744cc89c9a81aa7357480)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## PaddleSeg介绍\n",
    "\n",
    "PaddleSeg是基于飞桨PaddlePaddle的端到端图像分割套件，内置45+模型算法及140+预训练模型，支持配置化驱动和API调用开发方式，打通数据标注、模型开发、训练、压缩、部署的全流程，提供语义分割、交互式分割、Matting、全景分割四大分割能力，助力算法在医疗、工业、遥感、娱乐等场景落地应用。\n",
    "\n",
    "![](https://ai-studio-static-online.cdn.bcebos.com/3ca29143ca1f41ccadd6ad5301cf3ba08387891bd33d4f5dab3fbcefe287f801)\n",
    "\n",
    "本baseline使用PaddleSeg的MedicaSeg开发，github地址：[https://github.com/PaddlePaddle/PaddleSeg](https://github.com/PaddlePaddle/PaddleSeg)  \n",
    "\n",
    "\n",
    "老爷们，动动发财的小手，点点star为我们助力，您的支持就是我们的动力～～   \n",
    "![](https://ai-studio-static-online.cdn.bcebos.com/126d3c7a3789406bbace7861f70dd850b830329e8962429dbed902b0fe9bbf15)\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## nnunet高精度模型-训练-推理-提交全流程\n",
    "上一篇baseline使用vnet模型，使用的与处理策略非常简单，预测精度很低，本baseline使用nnunet 的cascade lowres模型，nnunet包含大量的trick，能够获得很高的精度。\n",
    "\n",
    "本baseline仅包含部分使用内容，完整的nnunet使用方案请参考：   \n",
    "nnunet教程： [https://aistudio.baidu.com/aistudio/projectdetail/4884907?contributionType=1](https://aistudio.baidu.com/aistudio/projectdetail/4884907?contributionType=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-26T02:49:15.422450Z",
     "iopub.status.busy": "2023-03-26T02:49:15.421822Z",
     "iopub.status.idle": "2023-03-26T02:50:52.374440Z",
     "shell.execute_reply": "2023-03-26T02:50:52.373268Z",
     "shell.execute_reply.started": "2023-03-26T02:49:15.422411Z"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/aistudio\r\n",
      "正克隆到 'PaddleSeg'...\r\n",
      "remote: Enumerating objects: 24255, done.\u001b[K\r\n",
      "remote: Counting objects: 100% (256/256), done.\u001b[K\r\n",
      "remote: Compressing objects: 100% (189/189), done.\u001b[K\r\n",
      "remote: Total 24255 (delta 131), reused 161 (delta 67), pack-reused 23999\u001b[K\r\n",
      "接收对象中: 100% (24255/24255), 347.80 MiB | 2.75 MiB/s, 完成.\r\n",
      "处理 delta 中: 100% (15755/15755), 完成.\r\n",
      "检查连接... 完成。\r\n",
      "/home/aistudio/PaddleSeg\r\n",
      "分支 develop 设置为跟踪来自 origin 的远程分支 develop。\r\n",
      "切换到一个新分支 'develop'\r\n"
     ]
    }
   ],
   "source": [
    "# step 1: 克隆PaddleSeg仓库\n",
    "%cd ~/\n",
    "!git clone https://github.com/PaddlePaddle/PaddleSeg.git\n",
    "%cd ~/PaddleSeg\n",
    "!git checkout develop    # develop分支目前支持nnformer,transunet,swinunet等多个算法，欢迎体验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-26T02:51:10.507540Z",
     "iopub.status.busy": "2023-03-26T02:51:10.506897Z",
     "iopub.status.idle": "2023-03-26T02:52:26.935385Z",
     "shell.execute_reply": "2023-03-26T02:52:26.934027Z",
     "shell.execute_reply.started": "2023-03-26T02:51:10.507495Z"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# step2: 解压数据到~/PaddleSeg/contrib/MedicalSeg/data/raw_data\n",
    "!mkdir ~/PaddleSeg/contrib/MedicalSeg/data\n",
    "!unzip -oq ~/data/data179474/base_train.zip -d ~/PaddleSeg/contrib/MedicalSeg/data/raw_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-27T10:04:29.568351Z",
     "iopub.status.busy": "2023-03-27T10:04:29.567416Z",
     "iopub.status.idle": "2023-03-27T10:04:29.814376Z",
     "shell.execute_reply": "2023-03-27T10:04:29.812119Z",
     "shell.execute_reply.started": "2023-03-27T10:04:29.568308Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# step 3: 删除原本的数据集压缩包，节约内存\n",
    "!rm -rf ~/data/data179474/base_train.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-27T06:24:22.863525Z",
     "iopub.status.busy": "2023-03-27T06:24:22.862917Z",
     "iopub.status.idle": "2023-03-27T06:24:23.104588Z",
     "shell.execute_reply": "2023-03-27T06:24:23.103446Z",
     "shell.execute_reply.started": "2023-03-27T06:24:22.863478Z"
    },
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 删除掉数据集中一个没用的文件夹，否则会报错\n",
    "!rm -rf ~/PaddleSeg/contrib/MedicalSeg/data/raw_data/.ipynb_checkpoints"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-27T14:07:26.001512Z",
     "iopub.status.busy": "2023-03-27T14:07:26.000873Z",
     "iopub.status.idle": "2023-03-27T14:07:35.438691Z",
     "shell.execute_reply": "2023-03-27T14:07:35.437778Z",
     "shell.execute_reply.started": "2023-03-27T14:07:26.001418Z"
    },
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\r\n",
      "Requirement already satisfied: pip in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (22.1.2)\r\n",
      "Collecting pip\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/07/51/2c0959c5adf988c44d9e1e0d940f5b074516ecc87e96b1af25f59de9ba38/pip-23.0.1-py3-none-any.whl (2.1 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m1.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m:00:01\u001b[0m\r\n",
      "\u001b[?25hInstalling collected packages: pip\r\n",
      "  Attempting uninstall: pip\r\n",
      "    Found existing installation: pip 22.1.2\r\n",
      "    Uninstalling pip-22.1.2:\r\n",
      "      Successfully uninstalled pip-22.1.2\r\n",
      "Successfully installed pip-23.0.1\r\n"
     ]
    }
   ],
   "source": [
    "!pip install --upgrade pip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-27T14:07:35.513586Z",
     "iopub.status.busy": "2023-03-27T14:07:35.512964Z",
     "iopub.status.idle": "2023-03-27T14:08:48.369738Z",
     "shell.execute_reply": "2023-03-27T14:08:48.367629Z",
     "shell.execute_reply.started": "2023-03-27T14:07:35.513560Z"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/aistudio/PaddleSeg/contrib/MedicalSeg\r\n",
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\r\n",
      "Collecting scikit-image\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2d/ba/63ce953b7d593bd493e80be158f2d9f82936582380aee0998315510633aa/scikit_image-0.19.3-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (13.5 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.5/13.5 MB\u001b[0m \u001b[31m1.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\r\n",
      "\u001b[?25hRequirement already satisfied: numpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 2)) (1.19.5)\r\n",
      "Requirement already satisfied: paddlepaddle-gpu>=2.2.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 3)) (2.4.0.post112)\r\n",
      "Collecting SimpleITK>=2.1.1\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e7/0d/a1f3351e7af5f8516a5326b53b7723f19f8fb64d5783c6ecc341db9f476f/SimpleITK-2.2.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (52.7 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m52.7/52.7 MB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\r\n",
      "\u001b[?25hRequirement already satisfied: PyYAML in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 5)) (5.1.2)\r\n",
      "Collecting pynrrd\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ee/43/1be50fe04e6a5df8cfdafa62151035a9358a768e26a5b9f33fc417e10bc6/pynrrd-1.0.0-py2.py3-none-any.whl (19 kB)\r\n",
      "Requirement already satisfied: tqdm in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 7)) (4.64.1)\r\n",
      "Requirement already satisfied: visualdl in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 8)) (2.4.0)\r\n",
      "Requirement already satisfied: sklearn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 9)) (0.0)\r\n",
      "Requirement already satisfied: filelock in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from -r requirements.txt (line 10)) (3.0.12)\r\n",
      "Collecting nibabel\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/89/51/c97641cc2cd1b3b14cdec54b4e86fe03fc59753ecd13dc67544716fb7353/nibabel-4.0.2-py3-none-any.whl (3.3 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.3/3.3 MB\u001b[0m \u001b[31m1.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\r\n",
      "\u001b[?25hCollecting pydicom\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/72/8342fdbd09a169c8552d1df40b3679776c45cabb47c667022afae50aecd4/pydicom-2.3.1-py3-none-any.whl (2.0 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.0/2.0 MB\u001b[0m \u001b[31m768.9 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:01\u001b[0m00:01\u001b[0m0m\r\n",
      "\u001b[?25hCollecting medpy\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/3b/70/c1fd5dd60242eee81774696ea7ba4caafac2bad8f028bba94b1af83777d7/MedPy-0.4.0.tar.gz (151 kB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m151.8/151.8 kB\u001b[0m \u001b[31m194.2 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\r\n",
      "\u001b[?25h  Preparing metadata (setup.py) ... \u001b[?25ldone\r\n",
      "\u001b[?25hRequirement already satisfied: scipy>=1.4.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image->-r requirements.txt (line 1)) (1.6.3)\r\n",
      "Collecting PyWavelets>=1.1.1\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ae/56/4441877073d8a5266dbf7b04c7f3dc66f1149c8efb9323e0ef987a9bb1ce/PyWavelets-1.3.0-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (6.4 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m6.4/6.4 MB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\r\n",
      "\u001b[?25hRequirement already satisfied: networkx>=2.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image->-r requirements.txt (line 1)) (2.4)\r\n",
      "Requirement already satisfied: packaging>=20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image->-r requirements.txt (line 1)) (21.3)\r\n",
      "Requirement already satisfied: imageio>=2.4.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image->-r requirements.txt (line 1)) (2.6.1)\r\n",
      "Requirement already satisfied: pillow!=7.1.0,!=7.1.1,!=8.3.0,>=6.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-image->-r requirements.txt (line 1)) (8.2.0)\r\n",
      "Collecting tifffile>=2019.7.26\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/38/85ae5ed77598ca90558c17a2f79ddaba33173b31cf8d8f545d34d9134f0d/tifffile-2021.11.2-py3-none-any.whl (178 kB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m178.9/178.9 kB\u001b[0m \u001b[31m448.5 kB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0ma \u001b[36m0:00:01\u001b[0m\r\n",
      "\u001b[?25hRequirement already satisfied: astor in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (0.8.1)\r\n",
      "Requirement already satisfied: protobuf<=3.20.0,>=3.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (3.20.0)\r\n",
      "Requirement already satisfied: paddle-bfloat==0.1.7 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (0.1.7)\r\n",
      "Requirement already satisfied: requests>=2.20.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (2.24.0)\r\n",
      "Requirement already satisfied: decorator in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (4.4.2)\r\n",
      "Requirement already satisfied: six in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (1.16.0)\r\n",
      "Requirement already satisfied: opt-einsum==3.3.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (3.3.0)\r\n",
      "Requirement already satisfied: typing-extensions in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from pynrrd->-r requirements.txt (line 6)) (4.3.0)\r\n",
      "Collecting nptyping\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b1/28/92edc05378175de13a3d4986cee7531853634a22b7e5e21a988fa84fde3f/nptyping-2.5.0-py3-none-any.whl (37 kB)\r\n",
      "Requirement already satisfied: bce-python-sdk in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->-r requirements.txt (line 8)) (0.8.53)\r\n",
      "Requirement already satisfied: flask>=1.1.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->-r requirements.txt (line 8)) (1.1.1)\r\n",
      "Requirement already satisfied: pandas in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->-r requirements.txt (line 8)) (1.1.5)\r\n",
      "Requirement already satisfied: matplotlib in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->-r requirements.txt (line 8)) (2.2.3)\r\n",
      "Requirement already satisfied: Flask-Babel>=1.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from visualdl->-r requirements.txt (line 8)) (1.0.0)\r\n",
      "Requirement already satisfied: scikit-learn in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from sklearn->-r requirements.txt (line 9)) (0.24.2)\r\n",
      "Requirement already satisfied: setuptools in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from nibabel->-r requirements.txt (line 11)) (56.2.0)\r\n",
      "Requirement already satisfied: Werkzeug>=0.15 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (0.16.0)\r\n",
      "Requirement already satisfied: click>=5.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (8.0.4)\r\n",
      "Requirement already satisfied: itsdangerous>=0.24 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (1.1.0)\r\n",
      "Requirement already satisfied: Jinja2>=2.10.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (3.0.0)\r\n",
      "Requirement already satisfied: pytz in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl->-r requirements.txt (line 8)) (2019.3)\r\n",
      "Requirement already satisfied: Babel>=2.3 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Flask-Babel>=1.0.0->visualdl->-r requirements.txt (line 8)) (2.8.0)\r\n",
      "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from packaging>=20.0->scikit-image->-r requirements.txt (line 1)) (3.0.9)\r\n",
      "Requirement already satisfied: idna<3,>=2.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (2.8)\r\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (2019.9.11)\r\n",
      "Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (1.25.11)\r\n",
      "Requirement already satisfied: chardet<4,>=3.0.2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from requests>=2.20.0->paddlepaddle-gpu>=2.2.0->-r requirements.txt (line 3)) (3.0.4)\r\n",
      "Requirement already satisfied: future>=0.6.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl->-r requirements.txt (line 8)) (0.18.0)\r\n",
      "Requirement already satisfied: pycryptodome>=3.8.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from bce-python-sdk->visualdl->-r requirements.txt (line 8)) (3.9.9)\r\n",
      "Requirement already satisfied: python-dateutil>=2.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl->-r requirements.txt (line 8)) (2.8.2)\r\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl->-r requirements.txt (line 8)) (1.1.0)\r\n",
      "Requirement already satisfied: cycler>=0.10 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from matplotlib->visualdl->-r requirements.txt (line 8)) (0.10.0)\r\n",
      "Collecting numpy\r\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/50/46/292cff79f5b30151b027400efdb3f740ea03271b600751b6696cf550c10d/numpy-1.21.5-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (15.7 MB)\r\n",
      "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m15.7/15.7 MB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m00:01\u001b[0m00:01\u001b[0m\r\n",
      "\u001b[?25hRequirement already satisfied: threadpoolctl>=2.0.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->-r requirements.txt (line 9)) (2.1.0)\r\n",
      "Requirement already satisfied: joblib>=0.11 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from scikit-learn->sklearn->-r requirements.txt (line 9)) (0.14.1)\r\n",
      "Requirement already satisfied: importlib-metadata in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from click>=5.1->flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (4.2.0)\r\n",
      "Requirement already satisfied: MarkupSafe>=2.0.0rc2 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (2.0.1)\r\n",
      "Requirement already satisfied: zipp>=0.5 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from importlib-metadata->click>=5.1->flask>=1.1.1->visualdl->-r requirements.txt (line 8)) (3.8.1)\r\n",
      "Building wheels for collected packages: medpy\r\n",
      "  Building wheel for medpy (setup.py) ... \u001b[?25ldone\r\n",
      "\u001b[?25h  Created wheel for medpy: filename=MedPy-0.4.0-py3-none-any.whl size=214957 sha256=f54cdc9c9273bdf039489bbc7bfd53743c71128803c960ef0a3d684f8b448fe4\r\n",
      "  Stored in directory: /home/aistudio/.cache/pip/wheels/3f/4e/7d/9458f3f38ea1eb250f2a2863feaa1aaccaee94e9c242d73f45\r\n",
      "Successfully built medpy\r\n",
      "Installing collected packages: SimpleITK, pydicom, numpy, tifffile, PyWavelets, nptyping, nibabel, scikit-image, pynrrd, medpy\r\n",
      "  Attempting uninstall: numpy\r\n",
      "    Found existing installation: numpy 1.19.5\r\n",
      "    Uninstalling numpy-1.19.5:\r\n",
      "      Successfully uninstalled numpy-1.19.5\r\n",
      "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\r\n",
      "parl 1.4.1 requires pyzmq==18.1.1, but you have pyzmq 23.2.1 which is incompatible.\u001b[0m\u001b[31m\r\n",
      "\u001b[0mSuccessfully installed PyWavelets-1.3.0 SimpleITK-2.2.1 medpy-0.4.0 nibabel-4.0.2 nptyping-2.5.0 numpy-1.21.5 pydicom-2.3.1 pynrrd-1.0.0 scikit-image-0.19.3 tifffile-2021.11.2\r\n",
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\r\n",
      "Requirement already satisfied: medpy in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (0.4.0)\r\n",
      "Requirement already satisfied: numpy>=1.11.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from medpy) (1.21.5)\r\n",
      "Requirement already satisfied: scipy>=1.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from medpy) (1.6.3)\r\n",
      "Requirement already satisfied: SimpleITK>=1.1.0 in /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages (from medpy) (2.2.1)\r\n"
     ]
    }
   ],
   "source": [
    "# step 4: 安装依赖包\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!pip install -r requirements.txt\n",
    "!pip install medpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-27T14:11:20.629385Z",
     "iopub.status.busy": "2023-03-27T14:11:20.628629Z",
     "iopub.status.idle": "2023-03-27T14:11:26.326455Z",
     "shell.execute_reply": "2023-03-27T14:11:26.325490Z",
     "shell.execute_reply.started": "2023-03-27T14:11:20.629342Z"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/aistudio/PaddleSeg/contrib/MedicalSeg\r\n",
      "^C\r\n"
     ]
    }
   ],
   "source": [
    "# step 5: nnunet cascade lowres训练，混合精度训练快一些，五折训练，这里使用fold 2，一共有0,1,2,3,4共五个fold。\n",
    "# 在训练之前，会先对数据进行预处理，如果觉得耗时过久怀疑出错，可以看一下PaddleSeg/contrib/Medicalseg/data目录里面是否有decathlon、preprocessed、cropped 3个文件夹\n",
    "# 没有这3个文件夹请耐心等待。\n",
    "\n",
    "# 为什么会报错json文件缺失？\n",
    "# 预处理的过程不可中断，如果中断可能导致部分文件丢失，可以把decathlon、preprocessed、cropped报错的文件夹删除，重新生成即可。\n",
    "\n",
    "# 什么是交叉训练？\n",
    "# 假设有100条数据，使用五折交叉验证训练。可以把数据集分为 ｜20｜20｜20｜20｜20｜，每次训练的时候，把其中一个作为验证集，其他作为训练集，这样可以得到5个模型，他们的验证集不重复。\n",
    "\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!python train.py --config configs/nnunet/msd_lung/nnunet_2d_msd_lung_fold3.yml \\\n",
    "        --log_iters 100 --precision fp16 --nnunet --save_dir output/2d_unet/fold3 --save_interval 2000 --use_vdl --resume_model output/2d_unet/fold3/iter_40000\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 为了防止内存溢出，请替换cascade预测下一阶段的部分代码\n",
    "!mv ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/cascade_utils.py ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/cascade_utils_backup.py \n",
    "!cp ~/cascade_utils.py ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-03-27T14:11:38.218491Z",
     "iopub.status.busy": "2023-03-27T14:11:38.217786Z",
     "iopub.status.idle": "2023-03-27T14:33:22.325945Z",
     "shell.execute_reply": "2023-03-27T14:33:22.324366Z",
     "shell.execute_reply.started": "2023-03-27T14:11:38.218453Z"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/home/aistudio/PaddleSeg/contrib/MedicalSeg\r\n",
      "/home/aistudio/PaddleSeg/contrib/MedicalSeg/medicalseg/cvlibs/config.py:451: UserWarning: Warning: The data dir now is /home/aistudio/PaddleSeg/contrib/MedicalSeg/data/, you should change the data_root in the global.yml if this directory didn't have enough space\r\n",
      "  .format(absolute_data_dir))\r\n",
      "Found existed data/decathlon, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed data/cropped, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed dataset_properties.pkl, please ensure your dataset_properties is preprocessed correctly!!!\r\n",
      "found unpacked dataset.\r\n",
      "loading dataset\r\n",
      "loading all case properties\r\n",
      "dataset split over! dataset mode: val, keys: ['06ac4e83-3fb1-456a-8522-d042a6f611bd'\r\n",
      " '0d60fa6b-4afc-40be-9480-c043bf254db1'\r\n",
      " '123c3bb3-95d4-42c0-8c13-260e5f0e978d'\r\n",
      " '1d2eb6ec-dd72-4926-ab9e-df9f58837b0a'\r\n",
      " '1f88054e-698a-4dd7-855a-11b44b1f0474'\r\n",
      " '254ee1fa-4cc2-4a21-b2cb-fc5cdf803a1e'\r\n",
      " '36e2cb91-948c-4d46-9da0-89d336c22321'\r\n",
      " '3c89df41-2c7c-4ac2-b1ea-ca0b837c716f'\r\n",
      " '48758001-eca1-4be7-8463-c43e42295cce'\r\n",
      " '4d87ef74-dfad-40d5-ae59-d2ee061f561e'\r\n",
      " '5a5afda4-132f-4fa9-8d96-d849464b6c2c'\r\n",
      " '67a20c6d-b4b5-4395-a371-7884d03b464e'\r\n",
      " '6d2f4818-aa98-4344-8c58-360548cad9e0'\r\n",
      " '70722d58-d936-47a0-a820-045f9c969c50'\r\n",
      " '7295fce3-c0ce-4bce-981a-80715048d55c'\r\n",
      " '73114a65-b720-48fe-ad55-51795f84d94f'\r\n",
      " '7385d9ea-c811-407e-b268-d19ec10f7583'\r\n",
      " '78e5f12e-c374-451c-9e71-490e806bc049'\r\n",
      " '88dc1426-f266-4b47-9409-a6ab71524ecc'\r\n",
      " '8ae2f496-5201-42ba-b750-3bf43a290681'\r\n",
      " '95cac378-5d8c-466e-8857-7544d9fa56ee'\r\n",
      " '987f503e-eb5c-46ac-8c95-6dc69f54b04e'\r\n",
      " '9b7034d8-6470-4c44-ad2a-5052f7187b53'\r\n",
      " 'a017d4ec-4110-4c7d-862a-0621428bb8f8'\r\n",
      " 'a651fb18-adc8-46e2-904f-bb30405af82f'\r\n",
      " 'ad3b1c18-c756-4491-9eb5-6c9c98640724'\r\n",
      " 'b81a2227-ecc0-42d7-8363-7a63997756fd'\r\n",
      " 'd3b7d60b-7360-4a41-b7f5-cebf76533817'\r\n",
      " 'dc2fd00c-893f-4d0b-b70d-2843707bcf2b'\r\n",
      " 'e3ddc3cf-05a9-4a5a-94b6-896e9012415a'\r\n",
      " 'f2fe5392-f51c-41dc-a273-cb9a2ae292a3'\r\n",
      " 'f412e7d1-e576-4dc7-b148-518501b368b6']\r\n",
      "2023-03-27 22:11:42 [INFO]\t\r\n",
      "---------------Config Information---------------\r\n",
      "batch_size: 1\r\n",
      "data_root: data/\r\n",
      "iters: 200000\r\n",
      "loss:\r\n",
      "  coef:\r\n",
      "  - 1\r\n",
      "  types:\r\n",
      "  - coef:\r\n",
      "    - 1.0\r\n",
      "    losses:\r\n",
      "    - batch_dice: true\r\n",
      "      do_bg: false\r\n",
      "      type: DC_and_CE_loss\r\n",
      "    plan_path: data/preprocessed/nnUNetPlansv2.1_plans_2D.pkl\r\n",
      "    stage: 0\r\n",
      "    type: MultipleLoss\r\n",
      "lr_scheduler:\r\n",
      "  end_lr: 0\r\n",
      "  learning_rate: 0.01\r\n",
      "  power: 0.9\r\n",
      "  type: PolynomialDecay\r\n",
      "model:\r\n",
      "  plan_path: data/preprocessed/nnUNetPlansv2.1_plans_2D.pkl\r\n",
      "  stage: 0\r\n",
      "  type: NNUNet\r\n",
      "optimizer:\r\n",
      "  momentum: 0.99\r\n",
      "  type: sgd\r\n",
      "  use_nesterov: true\r\n",
      "  weight_decay: 3.0e-05\r\n",
      "train_dataset:\r\n",
      "  cascade: false\r\n",
      "  cropped_data_dir: data/cropped\r\n",
      "  dataset_root: /\r\n",
      "  decathlon_dir: data/decathlon\r\n",
      "  fold: 3\r\n",
      "  mode: train\r\n",
      "  num_batches_per_epoch: 250\r\n",
      "  plan2d: true\r\n",
      "  plan3d: false\r\n",
      "  plans_name: nnUNetPlansv2.1_plans_2D.pkl\r\n",
      "  preprocessed_dir: data/preprocessed\r\n",
      "  raw_data_dir: data/raw_data\r\n",
      "  result_dir: /\r\n",
      "  stage: 0\r\n",
      "  type: MSDDataset\r\n",
      "  unpack_data: true\r\n",
      "val_dataset:\r\n",
      "  cascade: false\r\n",
      "  cropped_data_dir: data/cropped\r\n",
      "  dataset_root: /\r\n",
      "  decathlon_dir: data/decathlon\r\n",
      "  fold: 3\r\n",
      "  mode: val\r\n",
      "  num_batches_per_epoch: 50\r\n",
      "  plans_name: nnUNetPlansv2.1_plans_2D.pkl\r\n",
      "  preprocessed_dir: data/preprocessed\r\n",
      "  raw_data_dir: data/raw_data\r\n",
      "  result_dir: /\r\n",
      "  stage: 0\r\n",
      "  type: MSDDataset\r\n",
      "  unpack_data: true\r\n",
      "------------------------------------------------\r\n",
      "Found existed data/decathlon, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed data/cropped, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed dataset_properties.pkl, please ensure your dataset_properties is preprocessed correctly!!!\r\n",
      "Found existed plan file, please ensure your plan file is preprocessed correctly!!!\r\n",
      "found unpacked dataset.\r\n",
      "loading dataset\r\n",
      "loading all case properties\r\n",
      "dataset split over! dataset mode: train, keys: ['01a7d587-5815-479d-8292-9b4e6ee8f74b'\r\n",
      " '02a2bd9e-6589-4969-8826-b113340c0c15'\r\n",
      " '02d2627f-ed6a-4501-bae2-f5f173b822c9'\r\n",
      " '02de3b59-442b-42f9-9182-0c21c5eae0de'\r\n",
      " '05366407-726b-4731-9f17-f8e040892bfe'\r\n",
      " '06ef3e23-3fa5-4ce2-8539-8f95c541ecf5'\r\n",
      " '07f3a381-9abf-4de9-9c61-196915ea3369'\r\n",
      " '08c1e513-7c4a-44fb-a721-3ecd308cdb8b'\r\n",
      " '0902214a-af9f-4288-96f6-f01a86b359ac'\r\n",
      " '0b2be9e0-886b-4144-99f0-8bb4c6eaa848'\r\n",
      " '0c593893-56d7-4169-8f8e-703d9b205196'\r\n",
      " '105d4ce0-5521-4884-b34c-26d1aeb78b82'\r\n",
      " '1747470c-9609-4af4-ba20-5a7744efc43a'\r\n",
      " '1813da8e-0b71-4a6a-8e30-f171f46ab796'\r\n",
      " '192c1f1b-048a-434e-a1d1-af13648fdd30'\r\n",
      " '1dae67ab-ef78-4ca7-9537-ae0beeeb3d04'\r\n",
      " '1dfb73ea-9395-43e8-9f65-b966a8a3270e'\r\n",
      " '1f159998-7660-4021-bc19-0fb84dda1653'\r\n",
      " '1fd42364-61c1-434d-a19c-1234cd390768'\r\n",
      " '2487bde9-997c-4134-ae98-d26776ba47e0'\r\n",
      " '252b97fc-d773-4a68-99bc-89368c969dc8'\r\n",
      " '254abc57-faea-43cf-94b9-ee4e424f706b'\r\n",
      " '26719e9a-8f83-4860-bad8-65ee6645ea68'\r\n",
      " '26bc4a18-5af1-4764-8df6-2778386ed4c7'\r\n",
      " '28f4bd7e-a5d9-41c9-bb8c-6df33df072a1'\r\n",
      " '2ad40155-4c8e-4cb7-b6df-77c2267c4020'\r\n",
      " '2f64a001-4ce0-4d24-911b-b4d65e323bf7'\r\n",
      " '2fde6ab1-79e9-4491-b141-818382b2b7bc'\r\n",
      " '3060792f-3f89-4b42-a6c0-c531f4898ad5'\r\n",
      " '32447cb1-cd0a-4951-95b4-7f15850a2e4c'\r\n",
      " '32e7f5a0-aabe-41e8-8a55-d797d7ee0377'\r\n",
      " '365ac789-e415-412a-8391-fd9ec46fe258'\r\n",
      " '392ca4d8-c383-454f-b53b-a8494bfb2d0c'\r\n",
      " '3b1771a3-b132-4b7c-a6c9-4c2ecbe0d80e'\r\n",
      " '3e50e2c6-3d75-44dd-a836-4e5b5a4edb6f'\r\n",
      " '423d6020-d815-4fc3-b39a-416dfa4755bc'\r\n",
      " '42547a6b-3f65-40a9-861c-bff502c90919'\r\n",
      " '42d38991-7fce-4e55-92a7-52c4ba75297f'\r\n",
      " '452b0c14-aabe-4f29-ab20-4a316608a053'\r\n",
      " '45301564-771e-45b5-8a55-27f153c56d6f'\r\n",
      " '453d3aa1-2413-4249-a4ed-6fe58f3feed5'\r\n",
      " '47a8ab0f-69b3-4f5a-a5c5-793ef2e08279'\r\n",
      " '49964ec7-ecb5-4ba6-811a-ac64e0ea3037'\r\n",
      " '4afdcc6b-4794-4372-9135-5afe7f3d6e77'\r\n",
      " '4e9d3831-e8ad-45da-a2e2-471f0f03f148'\r\n",
      " '4f91f00a-769d-4991-89f8-4a6a586fae66'\r\n",
      " '51d8f17c-f3bc-479b-b188-f1d4fac9b491'\r\n",
      " '531e0b7f-21c8-4495-a364-5a306eff03fd'\r\n",
      " '53318585-da79-4d8c-a156-7379eddabd0f'\r\n",
      " '53405140-adf0-49b1-92f7-34e954496640'\r\n",
      " '547ee530-0862-4136-ba0c-288b5924545a'\r\n",
      " '58905356-36e1-4cd8-bbaa-c496c55122b6'\r\n",
      " '5bae4854-72a1-4b4e-b36a-0f46a57a064a'\r\n",
      " '5c138ba4-0fcc-4bb2-94ec-5ba436f09db9'\r\n",
      " '5c5952b1-29f5-4c41-86e8-fe62da95439e'\r\n",
      " '5d0632e0-9749-44c7-9e49-96f8e2bf0d59'\r\n",
      " '5eb9f537-b19b-46dd-b804-028d088f35ed'\r\n",
      " '6310c4f3-a70d-4a2c-9864-81f3e0984835'\r\n",
      " '648bdaa2-12a5-4fc7-bf13-6437fc5b270e'\r\n",
      " '65e762d8-e4dc-48d1-ada0-1309e4f26996'\r\n",
      " '675f9149-f3ff-4cf9-8c7a-e64165e483b2'\r\n",
      " '6ae1dfd4-a80d-4c88-a2f0-e02514fb16f4'\r\n",
      " '6ee45a83-ddd2-4782-8b5e-863234ce68a4'\r\n",
      " '7083823b-7397-4117-ba45-bab035894a05'\r\n",
      " '714d37e9-e11b-4864-bd75-1e197a0523b6'\r\n",
      " '7173b932-b073-4cb6-8a4e-ea09b284729e'\r\n",
      " '72ec310a-f5cf-4f04-aa7e-b968c24eb3a9'\r\n",
      " '75cbf6bc-7f48-4697-8e4c-f4b7e51cc8fe'\r\n",
      " '7741554d-6dba-4bcb-b650-a8fcc65b7863'\r\n",
      " '77588f58-69e8-4a00-a974-95d967aa0429'\r\n",
      " '78461665-928c-4b5c-82bc-e26e9913bd9c'\r\n",
      " '796ef616-9ee6-4fa6-bd07-ae88261df93f'\r\n",
      " '7b27eed5-4ec6-4a61-9455-8c82c1509ea5'\r\n",
      " '801df9c3-ef55-45b4-8a80-a0dde990da2e'\r\n",
      " '8169cbb7-b748-4ee3-a940-1ab4f77d14fe'\r\n",
      " '817b63c7-6cae-40fe-9847-c5c1e5cdb04b'\r\n",
      " '85288157-5fb8-4054-aac3-3674913246a7'\r\n",
      " '883634c5-8484-4eca-a694-825f4608bdba'\r\n",
      " '8a37774c-b160-409d-8bed-f93df23584c8'\r\n",
      " '8b7c7df8-8fb7-49c4-acc8-cc401649b5cf'\r\n",
      " '8c86dbec-e856-4a9d-8e3a-20299d18ba71'\r\n",
      " '8d2f8a4e-2c84-4b69-97c4-2fd56a8f6ec1'\r\n",
      " '911299ee-1b43-473d-8976-2d10f5be4cfa'\r\n",
      " '9163b5e5-2900-48b1-934f-8f991aaf0f3b'\r\n",
      " '9239d064-0941-4350-96ed-9b6f034ada84'\r\n",
      " '936b046f-e65d-4745-ae5f-9953a1cdf031'\r\n",
      " '95bf9a33-f027-4df7-b5ac-f7d123268008'\r\n",
      " '98948097-3789-40e7-8573-3b933c7b7e65'\r\n",
      " '9935327f-69a2-48f9-a7a6-53fb12aef8f0'\r\n",
      " '994b334e-831b-460b-b887-58af7d389c66'\r\n",
      " '9e846d62-f2a1-4a73-a2a3-905db7f1e8ca'\r\n",
      " '9fee7c1d-b921-4bcd-9563-f9a002161fc7'\r\n",
      " 'a0f0e7dd-9a85-4c58-bca9-7947e76fff2e'\r\n",
      " 'a5b178f7-5975-4cfd-a776-c0a4e74af08b'\r\n",
      " 'a5c25563-fcf7-406c-b49e-f4f67630cb84'\r\n",
      " 'a62e4f1b-0089-4730-9c6f-3a385723fb2f'\r\n",
      " 'a722cc46-1f6a-4776-9f81-578b5fc82f6a'\r\n",
      " 'a80a1255-f159-4856-a5fe-5b338f085daf'\r\n",
      " 'b2605322-17b5-4d34-8a4c-ed94baf1bc40'\r\n",
      " 'b37dec6e-2702-4691-afe3-58569a74979b'\r\n",
      " 'b66b0595-e794-4356-b2ee-25a19aeea969'\r\n",
      " 'bc873e36-344e-44d5-86a4-c4fcd6c7a6f2'\r\n",
      " 'bcef10b1-4c92-48b5-a30e-1ff5cf33b61c'\r\n",
      " 'be6bed28-eb8f-4cb8-911f-93f37cde92bb'\r\n",
      " 'c3591699-0467-4b5a-97c4-0bd42eef1834'\r\n",
      " 'c4d1e6ed-41ca-466f-bb77-cd4335fbfa43'\r\n",
      " 'c58583a9-0aa5-4c45-9c0c-3226175b9ff2'\r\n",
      " 'c6dabf28-c1f2-4d35-813f-1dcfdd92bdaf'\r\n",
      " 'c7f83f8d-a63f-4439-8e93-af122ffe9f61'\r\n",
      " 'c89f3e52-0cc5-400d-b3ee-9806df2562e8'\r\n",
      " 'c9bb5a87-1dc9-4a19-b375-841328b6e2e6'\r\n",
      " 'ccb8ff27-1a6b-4362-82f9-abad0579b177'\r\n",
      " 'cf3db076-7f00-4732-91cf-90970256943f'\r\n",
      " 'd1fcfb4d-d1a4-4077-819c-28703afab6aa'\r\n",
      " 'd613e6b5-f4a7-4cfe-b6cc-c47c12c1de43'\r\n",
      " 'd7f110dd-c932-4260-b2c8-ba14205118f1'\r\n",
      " 'd80974f6-c0b0-4055-906c-4afda3e2d7b3'\r\n",
      " 'dc1f2de1-b26b-4c6f-b688-ada83a1d0b87'\r\n",
      " 'de2e3836-4034-4b70-8387-4e1e2947d0e5'\r\n",
      " 'de751654-c9d0-4da4-ad69-da69121d161e'\r\n",
      " 'e06eb375-d43f-46b7-bbe4-a0d895a12c86'\r\n",
      " 'eb031ddf-5124-44f9-8e8b-b5b2cb5d563f'\r\n",
      " 'ede1f36d-8f9d-4042-89e5-6bb686675356'\r\n",
      " 'eeb32798-486b-4663-ab5e-54d32c164485'\r\n",
      " 'f2fb90a1-44fe-4e64-89e0-a38be52718fd'\r\n",
      " 'f34eb353-b265-45ee-863f-e7b3c9f8611c'\r\n",
      " 'f66a6fc1-80e9-4e39-a95c-c2f8cb039212'\r\n",
      " 'f7c197f9-a9fd-4b9d-b2bd-d602e5b76de2']\r\n",
      "Found existed data/decathlon, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed data/cropped, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed dataset_properties.pkl, please ensure your dataset_properties is preprocessed correctly!!!\r\n",
      "Found existed plan file, please ensure your plan file is preprocessed correctly!!!\r\n",
      "found unpacked dataset.\r\n",
      "loading dataset\r\n",
      "loading all case properties\r\n",
      "dataset split over! dataset mode: train, keys: ['01a7d587-5815-479d-8292-9b4e6ee8f74b'\r\n",
      " '02a2bd9e-6589-4969-8826-b113340c0c15'\r\n",
      " '02d2627f-ed6a-4501-bae2-f5f173b822c9'\r\n",
      " '02de3b59-442b-42f9-9182-0c21c5eae0de'\r\n",
      " '05366407-726b-4731-9f17-f8e040892bfe'\r\n",
      " '06ef3e23-3fa5-4ce2-8539-8f95c541ecf5'\r\n",
      " '07f3a381-9abf-4de9-9c61-196915ea3369'\r\n",
      " '08c1e513-7c4a-44fb-a721-3ecd308cdb8b'\r\n",
      " '0902214a-af9f-4288-96f6-f01a86b359ac'\r\n",
      " '0b2be9e0-886b-4144-99f0-8bb4c6eaa848'\r\n",
      " '0c593893-56d7-4169-8f8e-703d9b205196'\r\n",
      " '105d4ce0-5521-4884-b34c-26d1aeb78b82'\r\n",
      " '1747470c-9609-4af4-ba20-5a7744efc43a'\r\n",
      " '1813da8e-0b71-4a6a-8e30-f171f46ab796'\r\n",
      " '192c1f1b-048a-434e-a1d1-af13648fdd30'\r\n",
      " '1dae67ab-ef78-4ca7-9537-ae0beeeb3d04'\r\n",
      " '1dfb73ea-9395-43e8-9f65-b966a8a3270e'\r\n",
      " '1f159998-7660-4021-bc19-0fb84dda1653'\r\n",
      " '1fd42364-61c1-434d-a19c-1234cd390768'\r\n",
      " '2487bde9-997c-4134-ae98-d26776ba47e0'\r\n",
      " '252b97fc-d773-4a68-99bc-89368c969dc8'\r\n",
      " '254abc57-faea-43cf-94b9-ee4e424f706b'\r\n",
      " '26719e9a-8f83-4860-bad8-65ee6645ea68'\r\n",
      " '26bc4a18-5af1-4764-8df6-2778386ed4c7'\r\n",
      " '28f4bd7e-a5d9-41c9-bb8c-6df33df072a1'\r\n",
      " '2ad40155-4c8e-4cb7-b6df-77c2267c4020'\r\n",
      " '2f64a001-4ce0-4d24-911b-b4d65e323bf7'\r\n",
      " '2fde6ab1-79e9-4491-b141-818382b2b7bc'\r\n",
      " '3060792f-3f89-4b42-a6c0-c531f4898ad5'\r\n",
      " '32447cb1-cd0a-4951-95b4-7f15850a2e4c'\r\n",
      " '32e7f5a0-aabe-41e8-8a55-d797d7ee0377'\r\n",
      " '365ac789-e415-412a-8391-fd9ec46fe258'\r\n",
      " '392ca4d8-c383-454f-b53b-a8494bfb2d0c'\r\n",
      " '3b1771a3-b132-4b7c-a6c9-4c2ecbe0d80e'\r\n",
      " '3e50e2c6-3d75-44dd-a836-4e5b5a4edb6f'\r\n",
      " '423d6020-d815-4fc3-b39a-416dfa4755bc'\r\n",
      " '42547a6b-3f65-40a9-861c-bff502c90919'\r\n",
      " '42d38991-7fce-4e55-92a7-52c4ba75297f'\r\n",
      " '452b0c14-aabe-4f29-ab20-4a316608a053'\r\n",
      " '45301564-771e-45b5-8a55-27f153c56d6f'\r\n",
      " '453d3aa1-2413-4249-a4ed-6fe58f3feed5'\r\n",
      " '47a8ab0f-69b3-4f5a-a5c5-793ef2e08279'\r\n",
      " '49964ec7-ecb5-4ba6-811a-ac64e0ea3037'\r\n",
      " '4afdcc6b-4794-4372-9135-5afe7f3d6e77'\r\n",
      " '4e9d3831-e8ad-45da-a2e2-471f0f03f148'\r\n",
      " '4f91f00a-769d-4991-89f8-4a6a586fae66'\r\n",
      " '51d8f17c-f3bc-479b-b188-f1d4fac9b491'\r\n",
      " '531e0b7f-21c8-4495-a364-5a306eff03fd'\r\n",
      " '53318585-da79-4d8c-a156-7379eddabd0f'\r\n",
      " '53405140-adf0-49b1-92f7-34e954496640'\r\n",
      " '547ee530-0862-4136-ba0c-288b5924545a'\r\n",
      " '58905356-36e1-4cd8-bbaa-c496c55122b6'\r\n",
      " '5bae4854-72a1-4b4e-b36a-0f46a57a064a'\r\n",
      " '5c138ba4-0fcc-4bb2-94ec-5ba436f09db9'\r\n",
      " '5c5952b1-29f5-4c41-86e8-fe62da95439e'\r\n",
      " '5d0632e0-9749-44c7-9e49-96f8e2bf0d59'\r\n",
      " '5eb9f537-b19b-46dd-b804-028d088f35ed'\r\n",
      " '6310c4f3-a70d-4a2c-9864-81f3e0984835'\r\n",
      " '648bdaa2-12a5-4fc7-bf13-6437fc5b270e'\r\n",
      " '65e762d8-e4dc-48d1-ada0-1309e4f26996'\r\n",
      " '675f9149-f3ff-4cf9-8c7a-e64165e483b2'\r\n",
      " '6ae1dfd4-a80d-4c88-a2f0-e02514fb16f4'\r\n",
      " '6ee45a83-ddd2-4782-8b5e-863234ce68a4'\r\n",
      " '7083823b-7397-4117-ba45-bab035894a05'\r\n",
      " '714d37e9-e11b-4864-bd75-1e197a0523b6'\r\n",
      " '7173b932-b073-4cb6-8a4e-ea09b284729e'\r\n",
      " '72ec310a-f5cf-4f04-aa7e-b968c24eb3a9'\r\n",
      " '75cbf6bc-7f48-4697-8e4c-f4b7e51cc8fe'\r\n",
      " '7741554d-6dba-4bcb-b650-a8fcc65b7863'\r\n",
      " '77588f58-69e8-4a00-a974-95d967aa0429'\r\n",
      " '78461665-928c-4b5c-82bc-e26e9913bd9c'\r\n",
      " '796ef616-9ee6-4fa6-bd07-ae88261df93f'\r\n",
      " '7b27eed5-4ec6-4a61-9455-8c82c1509ea5'\r\n",
      " '801df9c3-ef55-45b4-8a80-a0dde990da2e'\r\n",
      " '8169cbb7-b748-4ee3-a940-1ab4f77d14fe'\r\n",
      " '817b63c7-6cae-40fe-9847-c5c1e5cdb04b'\r\n",
      " '85288157-5fb8-4054-aac3-3674913246a7'\r\n",
      " '883634c5-8484-4eca-a694-825f4608bdba'\r\n",
      " '8a37774c-b160-409d-8bed-f93df23584c8'\r\n",
      " '8b7c7df8-8fb7-49c4-acc8-cc401649b5cf'\r\n",
      " '8c86dbec-e856-4a9d-8e3a-20299d18ba71'\r\n",
      " '8d2f8a4e-2c84-4b69-97c4-2fd56a8f6ec1'\r\n",
      " '911299ee-1b43-473d-8976-2d10f5be4cfa'\r\n",
      " '9163b5e5-2900-48b1-934f-8f991aaf0f3b'\r\n",
      " '9239d064-0941-4350-96ed-9b6f034ada84'\r\n",
      " '936b046f-e65d-4745-ae5f-9953a1cdf031'\r\n",
      " '95bf9a33-f027-4df7-b5ac-f7d123268008'\r\n",
      " '98948097-3789-40e7-8573-3b933c7b7e65'\r\n",
      " '9935327f-69a2-48f9-a7a6-53fb12aef8f0'\r\n",
      " '994b334e-831b-460b-b887-58af7d389c66'\r\n",
      " '9e846d62-f2a1-4a73-a2a3-905db7f1e8ca'\r\n",
      " '9fee7c1d-b921-4bcd-9563-f9a002161fc7'\r\n",
      " 'a0f0e7dd-9a85-4c58-bca9-7947e76fff2e'\r\n",
      " 'a5b178f7-5975-4cfd-a776-c0a4e74af08b'\r\n",
      " 'a5c25563-fcf7-406c-b49e-f4f67630cb84'\r\n",
      " 'a62e4f1b-0089-4730-9c6f-3a385723fb2f'\r\n",
      " 'a722cc46-1f6a-4776-9f81-578b5fc82f6a'\r\n",
      " 'a80a1255-f159-4856-a5fe-5b338f085daf'\r\n",
      " 'b2605322-17b5-4d34-8a4c-ed94baf1bc40'\r\n",
      " 'b37dec6e-2702-4691-afe3-58569a74979b'\r\n",
      " 'b66b0595-e794-4356-b2ee-25a19aeea969'\r\n",
      " 'bc873e36-344e-44d5-86a4-c4fcd6c7a6f2'\r\n",
      " 'bcef10b1-4c92-48b5-a30e-1ff5cf33b61c'\r\n",
      " 'be6bed28-eb8f-4cb8-911f-93f37cde92bb'\r\n",
      " 'c3591699-0467-4b5a-97c4-0bd42eef1834'\r\n",
      " 'c4d1e6ed-41ca-466f-bb77-cd4335fbfa43'\r\n",
      " 'c58583a9-0aa5-4c45-9c0c-3226175b9ff2'\r\n",
      " 'c6dabf28-c1f2-4d35-813f-1dcfdd92bdaf'\r\n",
      " 'c7f83f8d-a63f-4439-8e93-af122ffe9f61'\r\n",
      " 'c89f3e52-0cc5-400d-b3ee-9806df2562e8'\r\n",
      " 'c9bb5a87-1dc9-4a19-b375-841328b6e2e6'\r\n",
      " 'ccb8ff27-1a6b-4362-82f9-abad0579b177'\r\n",
      " 'cf3db076-7f00-4732-91cf-90970256943f'\r\n",
      " 'd1fcfb4d-d1a4-4077-819c-28703afab6aa'\r\n",
      " 'd613e6b5-f4a7-4cfe-b6cc-c47c12c1de43'\r\n",
      " 'd7f110dd-c932-4260-b2c8-ba14205118f1'\r\n",
      " 'd80974f6-c0b0-4055-906c-4afda3e2d7b3'\r\n",
      " 'dc1f2de1-b26b-4c6f-b688-ada83a1d0b87'\r\n",
      " 'de2e3836-4034-4b70-8387-4e1e2947d0e5'\r\n",
      " 'de751654-c9d0-4da4-ad69-da69121d161e'\r\n",
      " 'e06eb375-d43f-46b7-bbe4-a0d895a12c86'\r\n",
      " 'eb031ddf-5124-44f9-8e8b-b5b2cb5d563f'\r\n",
      " 'ede1f36d-8f9d-4042-89e5-6bb686675356'\r\n",
      " 'eeb32798-486b-4663-ab5e-54d32c164485'\r\n",
      " 'f2fb90a1-44fe-4e64-89e0-a38be52718fd'\r\n",
      " 'f34eb353-b265-45ee-863f-e7b3c9f8611c'\r\n",
      " 'f66a6fc1-80e9-4e39-a95c-c2f8cb039212'\r\n",
      " 'f7c197f9-a9fd-4b9d-b2bd-d602e5b76de2']\r\n",
      "W0327 22:11:44.119385  1116 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 7.0, Driver API Version: 11.2, Runtime API Version: 11.2\r\n",
      "W0327 22:11:44.119441  1116 gpu_resources.cc:91] device: 0, cuDNN Version: 8.2.\r\n",
      "2023-03-27 22:11:45 [INFO]\tLoading pretrained model from output/2d_unet/fold3/iter_50000/model.pdparams\r\n",
      "2023-03-27 22:11:46 [INFO]\tThere are 134/134 variables loaded into NNUNet.\r\n",
      "2023-03-27 22:11:46 [INFO]\tLoaded trained params of model successfully\r\n",
      "Found existed data/decathlon, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed data/cropped, please ensure your dataset is preprocessed correctly!!!\r\n",
      "Found existed dataset_properties.pkl, please ensure your dataset_properties is preprocessed correctly!!!\r\n",
      "Found existed plan file, please ensure your plan file is preprocessed correctly!!!\r\n",
      "found unpacked dataset.\r\n",
      "loading dataset\r\n",
      "loading all case properties\r\n",
      "dataset split over! dataset mode: train, keys: ['01a7d587-5815-479d-8292-9b4e6ee8f74b'\r\n",
      " '02a2bd9e-6589-4969-8826-b113340c0c15'\r\n",
      " '02d2627f-ed6a-4501-bae2-f5f173b822c9'\r\n",
      " '02de3b59-442b-42f9-9182-0c21c5eae0de'\r\n",
      " '05366407-726b-4731-9f17-f8e040892bfe'\r\n",
      " '06ef3e23-3fa5-4ce2-8539-8f95c541ecf5'\r\n",
      " '07f3a381-9abf-4de9-9c61-196915ea3369'\r\n",
      " '08c1e513-7c4a-44fb-a721-3ecd308cdb8b'\r\n",
      " '0902214a-af9f-4288-96f6-f01a86b359ac'\r\n",
      " '0b2be9e0-886b-4144-99f0-8bb4c6eaa848'\r\n",
      " '0c593893-56d7-4169-8f8e-703d9b205196'\r\n",
      " '105d4ce0-5521-4884-b34c-26d1aeb78b82'\r\n",
      " '1747470c-9609-4af4-ba20-5a7744efc43a'\r\n",
      " '1813da8e-0b71-4a6a-8e30-f171f46ab796'\r\n",
      " '192c1f1b-048a-434e-a1d1-af13648fdd30'\r\n",
      " '1dae67ab-ef78-4ca7-9537-ae0beeeb3d04'\r\n",
      " '1dfb73ea-9395-43e8-9f65-b966a8a3270e'\r\n",
      " '1f159998-7660-4021-bc19-0fb84dda1653'\r\n",
      " '1fd42364-61c1-434d-a19c-1234cd390768'\r\n",
      " '2487bde9-997c-4134-ae98-d26776ba47e0'\r\n",
      " '252b97fc-d773-4a68-99bc-89368c969dc8'\r\n",
      " '254abc57-faea-43cf-94b9-ee4e424f706b'\r\n",
      " '26719e9a-8f83-4860-bad8-65ee6645ea68'\r\n",
      " '26bc4a18-5af1-4764-8df6-2778386ed4c7'\r\n",
      " '28f4bd7e-a5d9-41c9-bb8c-6df33df072a1'\r\n",
      " '2ad40155-4c8e-4cb7-b6df-77c2267c4020'\r\n",
      " '2f64a001-4ce0-4d24-911b-b4d65e323bf7'\r\n",
      " '2fde6ab1-79e9-4491-b141-818382b2b7bc'\r\n",
      " '3060792f-3f89-4b42-a6c0-c531f4898ad5'\r\n",
      " '32447cb1-cd0a-4951-95b4-7f15850a2e4c'\r\n",
      " '32e7f5a0-aabe-41e8-8a55-d797d7ee0377'\r\n",
      " '365ac789-e415-412a-8391-fd9ec46fe258'\r\n",
      " '392ca4d8-c383-454f-b53b-a8494bfb2d0c'\r\n",
      " '3b1771a3-b132-4b7c-a6c9-4c2ecbe0d80e'\r\n",
      " '3e50e2c6-3d75-44dd-a836-4e5b5a4edb6f'\r\n",
      " '423d6020-d815-4fc3-b39a-416dfa4755bc'\r\n",
      " '42547a6b-3f65-40a9-861c-bff502c90919'\r\n",
      " '42d38991-7fce-4e55-92a7-52c4ba75297f'\r\n",
      " '452b0c14-aabe-4f29-ab20-4a316608a053'\r\n",
      " '45301564-771e-45b5-8a55-27f153c56d6f'\r\n",
      " '453d3aa1-2413-4249-a4ed-6fe58f3feed5'\r\n",
      " '47a8ab0f-69b3-4f5a-a5c5-793ef2e08279'\r\n",
      " '49964ec7-ecb5-4ba6-811a-ac64e0ea3037'\r\n",
      " '4afdcc6b-4794-4372-9135-5afe7f3d6e77'\r\n",
      " '4e9d3831-e8ad-45da-a2e2-471f0f03f148'\r\n",
      " '4f91f00a-769d-4991-89f8-4a6a586fae66'\r\n",
      " '51d8f17c-f3bc-479b-b188-f1d4fac9b491'\r\n",
      " '531e0b7f-21c8-4495-a364-5a306eff03fd'\r\n",
      " '53318585-da79-4d8c-a156-7379eddabd0f'\r\n",
      " '53405140-adf0-49b1-92f7-34e954496640'\r\n",
      " '547ee530-0862-4136-ba0c-288b5924545a'\r\n",
      " '58905356-36e1-4cd8-bbaa-c496c55122b6'\r\n",
      " '5bae4854-72a1-4b4e-b36a-0f46a57a064a'\r\n",
      " '5c138ba4-0fcc-4bb2-94ec-5ba436f09db9'\r\n",
      " '5c5952b1-29f5-4c41-86e8-fe62da95439e'\r\n",
      " '5d0632e0-9749-44c7-9e49-96f8e2bf0d59'\r\n",
      " '5eb9f537-b19b-46dd-b804-028d088f35ed'\r\n",
      " '6310c4f3-a70d-4a2c-9864-81f3e0984835'\r\n",
      " '648bdaa2-12a5-4fc7-bf13-6437fc5b270e'\r\n",
      " '65e762d8-e4dc-48d1-ada0-1309e4f26996'\r\n",
      " '675f9149-f3ff-4cf9-8c7a-e64165e483b2'\r\n",
      " '6ae1dfd4-a80d-4c88-a2f0-e02514fb16f4'\r\n",
      " '6ee45a83-ddd2-4782-8b5e-863234ce68a4'\r\n",
      " '7083823b-7397-4117-ba45-bab035894a05'\r\n",
      " '714d37e9-e11b-4864-bd75-1e197a0523b6'\r\n",
      " '7173b932-b073-4cb6-8a4e-ea09b284729e'\r\n",
      " '72ec310a-f5cf-4f04-aa7e-b968c24eb3a9'\r\n",
      " '75cbf6bc-7f48-4697-8e4c-f4b7e51cc8fe'\r\n",
      " '7741554d-6dba-4bcb-b650-a8fcc65b7863'\r\n",
      " '77588f58-69e8-4a00-a974-95d967aa0429'\r\n",
      " '78461665-928c-4b5c-82bc-e26e9913bd9c'\r\n",
      " '796ef616-9ee6-4fa6-bd07-ae88261df93f'\r\n",
      " '7b27eed5-4ec6-4a61-9455-8c82c1509ea5'\r\n",
      " '801df9c3-ef55-45b4-8a80-a0dde990da2e'\r\n",
      " '8169cbb7-b748-4ee3-a940-1ab4f77d14fe'\r\n",
      " '817b63c7-6cae-40fe-9847-c5c1e5cdb04b'\r\n",
      " '85288157-5fb8-4054-aac3-3674913246a7'\r\n",
      " '883634c5-8484-4eca-a694-825f4608bdba'\r\n",
      " '8a37774c-b160-409d-8bed-f93df23584c8'\r\n",
      " '8b7c7df8-8fb7-49c4-acc8-cc401649b5cf'\r\n",
      " '8c86dbec-e856-4a9d-8e3a-20299d18ba71'\r\n",
      " '8d2f8a4e-2c84-4b69-97c4-2fd56a8f6ec1'\r\n",
      " '911299ee-1b43-473d-8976-2d10f5be4cfa'\r\n",
      " '9163b5e5-2900-48b1-934f-8f991aaf0f3b'\r\n",
      " '9239d064-0941-4350-96ed-9b6f034ada84'\r\n",
      " '936b046f-e65d-4745-ae5f-9953a1cdf031'\r\n",
      " '95bf9a33-f027-4df7-b5ac-f7d123268008'\r\n",
      " '98948097-3789-40e7-8573-3b933c7b7e65'\r\n",
      " '9935327f-69a2-48f9-a7a6-53fb12aef8f0'\r\n",
      " '994b334e-831b-460b-b887-58af7d389c66'\r\n",
      " '9e846d62-f2a1-4a73-a2a3-905db7f1e8ca'\r\n",
      " '9fee7c1d-b921-4bcd-9563-f9a002161fc7'\r\n",
      " 'a0f0e7dd-9a85-4c58-bca9-7947e76fff2e'\r\n",
      " 'a5b178f7-5975-4cfd-a776-c0a4e74af08b'\r\n",
      " 'a5c25563-fcf7-406c-b49e-f4f67630cb84'\r\n",
      " 'a62e4f1b-0089-4730-9c6f-3a385723fb2f'\r\n",
      " 'a722cc46-1f6a-4776-9f81-578b5fc82f6a'\r\n",
      " 'a80a1255-f159-4856-a5fe-5b338f085daf'\r\n",
      " 'b2605322-17b5-4d34-8a4c-ed94baf1bc40'\r\n",
      " 'b37dec6e-2702-4691-afe3-58569a74979b'\r\n",
      " 'b66b0595-e794-4356-b2ee-25a19aeea969'\r\n",
      " 'bc873e36-344e-44d5-86a4-c4fcd6c7a6f2'\r\n",
      " 'bcef10b1-4c92-48b5-a30e-1ff5cf33b61c'\r\n",
      " 'be6bed28-eb8f-4cb8-911f-93f37cde92bb'\r\n",
      " 'c3591699-0467-4b5a-97c4-0bd42eef1834'\r\n",
      " 'c4d1e6ed-41ca-466f-bb77-cd4335fbfa43'\r\n",
      " 'c58583a9-0aa5-4c45-9c0c-3226175b9ff2'\r\n",
      " 'c6dabf28-c1f2-4d35-813f-1dcfdd92bdaf'\r\n",
      " 'c7f83f8d-a63f-4439-8e93-af122ffe9f61'\r\n",
      " 'c89f3e52-0cc5-400d-b3ee-9806df2562e8'\r\n",
      " 'c9bb5a87-1dc9-4a19-b375-841328b6e2e6'\r\n",
      " 'ccb8ff27-1a6b-4362-82f9-abad0579b177'\r\n",
      " 'cf3db076-7f00-4732-91cf-90970256943f'\r\n",
      " 'd1fcfb4d-d1a4-4077-819c-28703afab6aa'\r\n",
      " 'd613e6b5-f4a7-4cfe-b6cc-c47c12c1de43'\r\n",
      " 'd7f110dd-c932-4260-b2c8-ba14205118f1'\r\n",
      " 'd80974f6-c0b0-4055-906c-4afda3e2d7b3'\r\n",
      " 'dc1f2de1-b26b-4c6f-b688-ada83a1d0b87'\r\n",
      " 'de2e3836-4034-4b70-8387-4e1e2947d0e5'\r\n",
      " 'de751654-c9d0-4da4-ad69-da69121d161e'\r\n",
      " 'e06eb375-d43f-46b7-bbe4-a0d895a12c86'\r\n",
      " 'eb031ddf-5124-44f9-8e8b-b5b2cb5d563f'\r\n",
      " 'ede1f36d-8f9d-4042-89e5-6bb686675356'\r\n",
      " 'eeb32798-486b-4663-ab5e-54d32c164485'\r\n",
      " 'f2fb90a1-44fe-4e64-89e0-a38be52718fd'\r\n",
      " 'f34eb353-b265-45ee-863f-e7b3c9f8611c'\r\n",
      " 'f66a6fc1-80e9-4e39-a95c-c2f8cb039212'\r\n",
      " 'f7c197f9-a9fd-4b9d-b2bd-d602e5b76de2']\r\n",
      "start evaluating...\r\n",
      "06ac4e83-3fb1-456a-8522-d042a6f611bd (2, 98, 526, 526)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "separate z, order in z is 0 order inplane is 1.\r\n",
      "0d60fa6b-4afc-40be-9480-c043bf254db1 (2, 92, 408, 408)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "separate z, order in z is 0 order inplane is 1.\r\n",
      "123c3bb3-95d4-42c0-8c13-260e5f0e978d (2, 108, 624, 624)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "separate z, order in z is 0 order inplane is 1.\r\n",
      "1d2eb6ec-dd72-4926-ab9e-df9f58837b0a (2, 228, 449, 449)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "no separate z, order 1.\r\n",
      "1f88054e-698a-4dd7-855a-11b44b1f0474 (2, 93, 545, 545)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "separate z, order in z is 0 order inplane is 1.\r\n",
      "254ee1fa-4cc2-4a21-b2cb-fc5cdf803a1e (2, 112, 641, 641)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "separate z, order in z is 0 order inplane is 1.\r\n",
      "36e2cb91-948c-4d46-9da0-89d336c22321 (2, 291, 451, 451)\r\n",
      "debug: mirroring True mirror_axes (0, 1)\r\n",
      "no separate z, order 1.\r\n"
     ]
    }
   ],
   "source": [
    "# step 6: fold2的数据集划分验证一下精度，运行一下，生成下个命令需要用的json，如果不使用后处理策略可以不运行\n",
    "# 有的数据很大，可能导致内存溢出，可以切换A100环境预测下一阶段\n",
    "# 可以除去--predict_next_stage参数，不预测该数据的下一阶段\n",
    "\n",
    "# predict_next_stage的作用是什么？\n",
    "# cascade unet分为2阶段，第一阶段会把分辨率降低进行训练，增强模型的感受野。第二阶段会把第一阶段的模型预测结果和原始数据一起作为输入，所以训练low resolution模型后，\n",
    "# 需要预测下一阶段的输入数据。\n",
    "\n",
    "# 交叉验证和二阶段训练结合为什么这么难懂？\n",
    "# 一阶段交叉训练：｜20｜20｜20｜20｜20｜\n",
    "# 二阶段交叉训练：｜20（concat（原始数据，一阶段预测的结果））｜20（concat（原始数据，一阶段预测的结果））｜20（concat（原始数据，一阶段预测的结果））｜20（concat（原始数据，一阶段预测的结果））｜20（concat（原始数据，一阶段预测的结果））｜\n",
    "# 为了训练第二阶段，需要使用五个模型预测整个数据集，这样二阶段才能训练。\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!python nnunet/single_fold_eval.py --config configs/nnunet/msd_lung/nnunet_2d_msd_lung_fold3.yml \\\n",
    "        --model_path output/2d_unet/fold3/iter_50000/model.pdparams --val_save_folder output/2d_val \\\n",
    "        --precision fp16\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "## 可选步骤：先运行step 7，如果提示内存溢出则运行此命令，替代原本的推理代码\n",
    "!mv ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/predict_utils.py ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/predict_utils_old.py \n",
    "!cp ~/predict_utils.py ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# step 7: 推理\n",
    "\n",
    "# 为什么要用json文件？\n",
    "# nnunet采用了后处理策略对预测结果进行修正，但是后处理策略是否一定会涨点呢？对每个类别，对比使用了后处理和不使用后处理策略的精度，这样就可以决定每个类别是否使用后处理策略。\n",
    "# 需要后处理涨点的类别存放在json中，这是json的作用。\n",
    "\n",
    "# 是否一定要该折对应的json？\n",
    "# 不是，json只是决定某个类别是否使用后处理，即使使用其他折的json，也可以预测，但是后处理的类别可能会错误，这个时候后处理的预测结果不可靠。\n",
    "\n",
    "# 不希望使用后处理策略怎么办？\n",
    "# 命令中加上--disable_postprocessing即可\n",
    "\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!python nnunet/predict.py --image_folder data/decathlon/imagesTs \\\n",
    "    --output_folder ~/submit \\\n",
    "    --plan_path data/preprocessed/nnUNetPlansv2.1_plans_3D.pkl \\\n",
    "    --model_paths output/cascade_lowres/fold2/iter_30000/model.pdparams \\\n",
    "    --postprocessing_json_path output/cascade_lowres_val/postprocessing.json --model_type cascade_lowres \\\n",
    "    --num_threads_preprocessing 1 --num_threads_nifti_save 1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# step 8: 打包提交，生成submit.zip,在/home/aistudio目录下\n",
    "!zip -j ~/submit.zip ~/submit/*.nii.gz\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## nnunet高精度模型 推理-提交全流程\n",
    "使用提供的权重，快速进行推理提交"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# step 1: 克隆PaddleSeg仓库--已有请忽略\n",
    "%cd ~/\n",
    "!git clone https://github.com/PaddlePaddle/PaddleSeg.git\n",
    "%cd ~/PaddleSeg\n",
    "!git checkout develop    # develop分支目前支持nnformer,transunet,swinunet等多个算法，欢迎体验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# step2: 解压数据到~/PaddleSeg/contrib/MedicalSeg/data/raw_data  ---  如果已经运行过数据预处理，请忽略。~/PaddleSeg/contrib/MedicalSeg/data这个目录下是否有decalthon和preprocess这2个文件夹\n",
    "!mkdir ~/PaddleSeg/contrib/MedicalSeg/data\n",
    "!unzip -oq ~/data/data179474/base_train.zip -d ~/PaddleSeg/contrib/MedicalSeg/data/raw_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# step 3: 删除原本的数据集压缩包，节约内存\n",
    "!rm -rf ~/data/data179474/base_train.zip"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# 删除掉数据集中一个没用的文件夹，否则会报错\n",
    "!rm -rf ~/PaddleSeg/contrib/MedicalSeg/data/raw_data/.ipynb_checkpoints"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# step 4: 安装依赖包 --- 已安装请忽略\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!pip install -r requirements.txt\n",
    "!pip install medpy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# step 5: fold2的数据集验证一下精度，这里的目的是触发数据预处理，不然step 6没法推理，如果PaddleSeg/contrib/MedicalSeg/data/decathlon文件夹存在，可以跳过\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!python nnunet/single_fold_eval.py --config ~/configs/nnunet_fold2.yml \\\n",
    "        --model_path ~/baseline_model/model.pdparams --val_save_folder output/cascade_lowres_val \\\n",
    "        --precision fp16\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "## 可选步骤：先运行step 6，如果提示内存溢出则运行此命令，替代原本的推理代码\n",
    "!mv ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/predict_utils.py ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/predict_utils_old.py \n",
    "!cp ~/predict_utils.py ~/PaddleSeg/contrib/MedicalSeg/nnunet/utils/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true,
    "tags": []
   },
   "outputs": [],
   "source": [
    "# step 6: 使用提供的权重推理，nnunet默认使用tta策略，速度比较慢\n",
    "%cd ~/PaddleSeg/contrib/MedicalSeg/\n",
    "!python nnunet/predict.py --image_folder data/decathlon/imagesTs \\\n",
    "    --output_folder ~/submit \\\n",
    "    --plan_path data/preprocessed/nnUNetPlansv2.1_plans_3D.pkl \\\n",
    "    --model_paths ~/baseline_model/model.pdparams \\\n",
    "    --postprocessing_json_path ~/baseline_model/postprocessing.json --model_type cascade_lowres \\\n",
    "    --num_threads_preprocessing 1 --num_threads_nifti_save 1 --precision fp16\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# step 7: 打包提交，生成submit.zip,在/home/aistudio目录下\n",
    "!zip -j ~/submit.zip ~/submit/*.nii.gz\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 上分策略\n",
    "本baseline只提供了nnunet cascade lowres的单折模型，并未使用多折模型ensemble以及多模型间ensemble，选手可以自行尝试。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "py35-paddle1.2.0"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
